home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / perl5 / Debian / DocBase / Programs / Dhelp.pm next >
Encoding:
Perl POD Document  |  2008-09-07  |  2.2 KB  |  104 lines

  1. # vim:cindent:ts=2:sw=2:et:fdm=marker:cms=\ #\ %s
  2. #
  3. # $Id: Dhelp.pm 143 2008-04-27 08:07:20Z robert $
  4. #
  5.  
  6. package Debian::DocBase::Programs::Dhelp;
  7.  
  8. use Exporter();
  9. use strict;
  10. use warnings;
  11.  
  12. use vars qw(@ISA @EXPORT);
  13. @ISA = qw(Exporter);
  14. @EXPORT = qw(RegisterDhelp UnregisterDhelp);
  15.  
  16. use Carp;
  17. use Debian::DocBase::Common;
  18. use Debian::DocBase::Utils;
  19.  
  20. my $DHELP_PARSE     = "/usr/sbin/dhelp_parse";
  21.  
  22. # executes `/usr/sbin/dhelp_parse $arg $@dirs'
  23. # $arg should be `-d' or `-a' or `-r'
  24. sub _ExecuteDhelpParse($$) { # {{{
  25.   my $arg   = shift;
  26.   my $dirs  = shift;
  27.  
  28.   return 0 if $#{$dirs} < 0 and $arg ne '-r';
  29.  
  30.   Execute($DHELP_PARSE, $arg, @$dirs) if ($opt_update_menus);
  31.  
  32. } # }}}
  33.  
  34.  
  35.  
  36. sub _GetDocFileList($$) { # {{{
  37.   my $documents = shift;  # in parameter
  38.   my $docfiles  = shift;  # out parameter
  39.  
  40.   foreach my $doc (@$documents) {
  41.     my $docid   = $doc->GetDocumentID();
  42.     my $docfile = $VAR_CTRL_DIR . "/" . $docid;
  43.     next unless -f $docfile;
  44.     push(@$docfiles, $docfile);
  45.   }
  46. }   # }}}
  47.  
  48. # Main functions of the module
  49.  
  50. # Unregistering documents from dhelp
  51. # Must be called BEFORE the new contents is written
  52. # to /var/lib/doc-base/documents/
  53.   sub UnregisterDhelp(@) {  # {{{
  54.   my @documents     = @_;
  55.   my @docfiles      = ();
  56.  
  57.   Debug("UnregisterDhelp started");
  58.  
  59.   _GetDocFileList(\@documents, \@docfiles);
  60.  
  61.   _ExecuteDhelpParse("-d", \@docfiles);
  62.  
  63.   Debug("UnregisterDhelp finished");
  64.  
  65.   undef @docfiles;
  66.  
  67. } # }}}
  68.  
  69. # Registering documents to dhelp
  70. # Must be called before AFTER new contents is written
  71. # to /var/lib/doc-base/documents/
  72. sub RegisterDhelp($$@) {  # {{{
  73.   my $showinfo      = shift;
  74.   my $register_all  = shift;
  75.   my @documents     = @_;
  76.   my @docfiles      = ();
  77.  
  78.   Debug("RegisterDhelp started");
  79.  
  80.   if (-x $DHELP_PARSE) {
  81.     Inform("Registering documents with dhelp...") if $showinfo and $opt_update_menus;
  82.   } else {
  83.     Debug("Skipping execution of $DHELP_PARSE - dhelp package doesn't seem to be installed");
  84.     return;
  85.   }
  86.  
  87.   if ($register_all) {
  88.     _ExecuteDhelpParse("-r", ());
  89.   }
  90.   else
  91.   {
  92.     _GetDocFileList(\@documents, \@docfiles);
  93.  
  94.     _ExecuteDhelpParse("-a", \@docfiles) if @docfiles;
  95.   }
  96.  
  97.   Debug("RegisterDhelp finished");
  98.  
  99.   undef @docfiles;
  100.  
  101. } # }}}
  102.  
  103. 1;
  104.